<template>
  <div></div>
</template>
<script>
import { mapState } from 'vuex';
import { i18nRender } from '@/locales';
export default {
  name: 'GroupDeleteMsg',
  data() {
    return {
      filterMenu: [
        '/monitor_overview_global_menu',
        '/private_presale_menu',
        '/setting_contact_menu',
        '/private_accountsetting_menu',
        '/private_theme_menu',
        '/private_version_menu',
      ],
    };
  },
  computed: {
    ...mapState('Group', ['groupId', 'groupMap']),
  },
  beforeCreate() {
    this.$EventBus.$on('GROUP_DELETED_EVENT', (ret) => {
      const data = typeof ret === 'object' ? ret : JSON.parse(ret);
      const path = this.$route.path;
      const currentGroup = this.groupMap[this.groupId];
      if (data.groupId == this.groupId) {
        if (this.filterMenu.indexOf(path) > -1) {
          this.updataGroupTree();
          return;
        }
        this.$confirm({
          title: i18nRender('system.account'),
          content: `${i18nRender('system.systemcheck')}${
            currentGroup.name || ''
          }${i18nRender('system.project')}${
            data.deleteSceneType == 'EMULATION_SIMULATION_NETWORTK'
              ? i18nRender('system.returnrt')
              : i18nRender('system.delete')
          },${i18nRender('system.systemturn')}`,
          okText: i18nRender('upgradeLog.ok'),
          cancelText: i18nRender('system.cancle'),
          onOk: () => {
            this.updataGroupTree();
            this.$router.replace('/');
          },
        });
      } else {
        this.updataGroupTree();
      }
    });
  },
  methods: {
    async updataGroupTree() {
      await this.$store.dispatch('Group/getGroupTree');
      const groupId = this.$store.state.Group.grouproot?.groupId;
      this.$store.commit('Group/SET_GROUPID', groupId);
    },
  },
};
</script>
